<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>15.1.DOM-操作元素-其他元素属性的操作-修改元素属性</title>
    <style>
        img {
            display: block;
            width: 300px;
        }
    </style>
</head>

<body>
    <button id="l">天外</button>
    <button id="r">来物</button>
    <img src="images/DOM-1.jpg" alt="" title="天外">

    <script>
        // 修改元素属性 src
        // 1.获取元素
        var l = document.getElementById('l');
        var r = document.getElementById('r');
        var img = document.querySelector('img');
        // 2.注册事件
        l.onclick = function () {
            img.src = 'images/DOM-1.jpg';
            img.title = '天外';
        }
        r.onclick = function () {
            img.src = 'images/DOM-2.jpg';
            img.title = '来物';
        }
    </script>
</body>

</html>